package com.example.administrator.uitest.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.uitest.R;
import com.example.administrator.uitest.intface.DoView;
import com.example.administrator.uitest.request.Regiest_Request;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by Administrator on 2018/6/28 0028.
 */

public class AgrestActivity extends Activity{
    private Button btn5;
    private EditText ed_pwd,ed_userId,ed_name;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layoutzc);
        btn5=findViewById(R.id.btn5);
        ed_pwd = findViewById(R.id.ed_pwd);
        ed_userId = findViewById(R.id.ed_userId);
        ed_name = findViewById(R.id.ed_name);
        btn5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uName ="";
                try {
                    uName = URLEncoder.encode(ed_name.getText().toString(),"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                String params = "userId="+ed_userId.getText().toString()+"&userPwd="+ed_pwd.getText().toString()+"&userName="+uName;
                Regiest_Request regiest_request = new Regiest_Request(AgrestActivity.this,params);
                regiest_request.conn(new DoView() {
                    @Override
                    public void setSuccessfulView(Object object) {
                        if(object.toString().equals("true")){
                            Toast.makeText(AgrestActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                            finish();
                        }else {
                            Toast.makeText(AgrestActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void setFiledView(Object object) {
                        Toast.makeText(AgrestActivity.this, "出错啦", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }
}
